import { writeFileSync } from "fs";
import BaseVo from "./BaseVo";
import path = require("path");
import Utils from "../utils/Utils";
import LocalStore from "../utils/LocalStore";

export default class AppVo extends BaseVo {
    constructor() {
        super();
    }

    /**自动记录的书签 */
    auto: { [key: string]: { charIndex: number; }; } = {};
    // /**阅读模式 */
    // readModel: number = 1;
    // /**每页行数 */
    // pageLine: number = 5;
    // /**每行字符 */
    // lineChar: number = 20;


    public initData(): void {
        let data = LocalStore.getAll();

        this.auto = JSON.parse(data.auto || "{}");
        // this.pageLine = Number(data.pageLine || "5");
        // this.lineChar = Number(data.lineChar || "50");
        // this.readModel = Number(data.readModel || "1");

        this.asyncToStore();
    }

    private asyncToStore() {
        let _obj = {
            auto: JSON.stringify(this.auto),
            // readModel: String(this.readModel),
            // pageLine: String(this.pageLine),
            // lineChar: String(this.lineChar)
        };

        // writeFileSync(path.join(Utils.root, "./res/app_data.json"), JSON.stringify(_obj, null, 4));
        LocalStore.setAll(_obj);
    }

    public destory(): void {
        
    }
}